﻿Imports iConverter.Contracts
Imports System.Drawing
Imports System.Configuration
Imports iConverter.Extensions
Imports iConverter.Models
Imports iConverter.Core

Namespace Extensions
    ''' <summary>
    ''' 扩展插件的基类
    ''' </summary>
    ''' <remarks></remarks>
    Public MustInherit Class Plugin
        Implements IDisposable

        ''' <summary>
        ''' 包含自己的提供器
        ''' </summary>
        ''' <remarks></remarks>
        Dim _provider As PluginProvider



        ''' <summary>
        ''' 创建新的插件实例
        ''' </summary>
        ''' <param name="provider">提供插件的提供器</param>
        ''' <param name="plugin">插件对象</param>
        ''' <remarks></remarks>
        Friend Sub New(provider As PluginProvider, plugin As Object)
            Me._provider = provider

            Me._plugin = DirectCast(plugin, IPlugin)
            Me._metadata = DirectCast(plugin, IPluginMetadata)


            Me._sIcon = ExtensionsFactory.TryGetImageSource(Me.Metadata.SmallIcon)

            Me._icon = ExtensionsFactory.TryGetImageSource(Me.Metadata.Icon)

        End Sub


        ''' <summary>
        ''' 插件对象
        ''' </summary>
        ''' <remarks></remarks>
        Dim _plugin As IPlugin

        ''' <summary>
        ''' 插件元数据
        ''' </summary>
        ''' <remarks></remarks>
        Dim _metadata As IPluginMetadata

        ''' <summary>
        ''' 插件元数据
        ''' </summary>
        ''' <remarks></remarks>
        Private ReadOnly Property Metadata() As IPluginMetadata
            Get
                Return _metadata
            End Get
        End Property
        ''' <summary>
        ''' 插件对象
        ''' </summary>
        ''' <remarks></remarks>
        Private ReadOnly Property Plugin() As IPlugin
            Get
                Return _plugin
            End Get
        End Property

        ''' <summary>
        ''' 包含自己的提供器
        ''' </summary>
        ''' <remarks></remarks>
        Friend ReadOnly Property Provider() As PluginProvider
            Get
                Return _provider
            End Get
        End Property


#Region "元数据"

        ''' <summary>
        ''' 获取插件描述
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property Description As String
            Get
                Return Me.Metadata.Description
            End Get
        End Property

        ''' <summary>
        ''' 获取插件名称
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property Name As String
            Get
                Return Me.Metadata.Name
            End Get
        End Property



        ''' <summary>
        ''' 获取插件的GUID
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property ID As System.Guid
            Get
                Return Me.Metadata.ID
            End Get
        End Property


        Dim _icon As ImageSource

        ''' <summary>
        ''' 获取用于显示的图标
        ''' </summary>
        ''' <value></value>
        ''' <returns>如果没有可用图标则返回Nothing，否则返回图标的Bitmap对象</returns>
        ''' <remarks>大小在32*32内为最佳</remarks>
        Public ReadOnly Property Icon As ImageSource
            Get
                Return Me._icon
            End Get
        End Property


        Dim _sIcon As ImageSource

        ''' <summary>
        ''' 获取小图标
        ''' </summary>
        ''' <value></value>
        ''' <returns>如果没有可用图标则返回Nothing，否则返回图标的Bitmap对象</returns>
        ''' <remarks>用于显示在菜单中（16 x 16 )小图标</remarks>
        Public ReadOnly Property SmallIcon As ImageSource
            Get
                Return Me._sIcon
            End Get
        End Property
#End Region





#Region "插件 "

        ''' <summary>
        ''' 获取一个值，来指示插件是否可以运行。
        ''' </summary>
        Public ReadOnly Property CheckCanRun As Boolean
            Get
                Return Me.Plugin.CheckCanRun
            End Get
        End Property

        ''' <summary>
        ''' 获取插件类型
        ''' </summary>
        Protected Friend ReadOnly Property PluginType As Contracts.PluginTypes
            Get
                Return Me.Plugin.PluginType
            End Get
        End Property
#End Region



#Region "IDisposable Support"
        Protected disposedValue As Boolean ' 检测冗余的调用

        ' IDisposable
        Protected MustOverride Sub Dispose(disposing As Boolean)



        'Protected Overrides Sub Finalize()
        '    ' 不要更改此代码。请将清理代码放入上面的 Dispose(ByVal disposing As Boolean)中。
        '    Dispose(False)
        '    MyBase.Finalize()
        'End Sub

        ' Visual Basic 添加此代码是为了正确实现可处置模式。
        Public Sub Dispose() Implements IDisposable.Dispose
            ' 不要更改此代码。请将清理代码放入上面的 Dispose(ByVal disposing As Boolean)中。
            Dispose(True)
            GC.SuppressFinalize(Me)
        End Sub
#End Region

    End Class


End Namespace
